package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.qf.mapper.OrderMapper;
import com.qf.pojo.Car;
import com.qf.pojo.City;
import com.qf.pojo.Order;
import com.qf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Mr.Liu
 * @date 2021/12/16 11:39
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    /**
     * 查询取车地点
     * @param getid
     * @return
     */
    @Override
    public City findCityByGetid(Integer getid) {
        City getCity = orderMapper.findCityByGetid(getid);
        if(getCity!=null){
            return getCity;
        }
        return null;
    }

    /**
     * 查询还车地点
     * @param backid
     * @return
     */
    @Override
    public City findCityByBackid(Integer backid) {
        City backCity = orderMapper.findCityByBackid(backid);
        if(backCity!=null){
            return backCity;
        }
        return null;
    }

    /**
     * 通过id查询车辆
     * @param cid
     * @return
     */
    @Override
    public Car findCarById(Integer cid) {
        Car car = orderMapper.findCarById(cid);
        if(car!=null){
            return car;
        }
        return null;
    }

    /**
     * 插入订单
     * @param order
     * @return
     */
    @Override
    public Integer insertOrder(Order order) {
        Integer integer = orderMapper.insertOrder(order);
        if(integer!=null){
            return integer;
        }
        return null;
    }

    /**
     * 查询订单总数
     * @return
     */
    @Override
    public Integer findTotalSize(Integer uid) {
        Integer total = orderMapper.findTotalSize(uid);
        if(total!=null){
         return total;
        }
        return null;
    }

    /**
     * 查询所有订单
     * @return
     */
    @Override
    public List<Order> findAllOrder(Integer pageNum,Integer pageSize,Integer uid) {
        PageHelper.startPage(pageNum,pageSize);
        List<Order> orders = orderMapper.findAllOrder(uid);
        if(orders!=null){
            return orders;
        }
        return null;
    }
}
